package com.woniu.user.controller;

import com.woniu.common.entity.*;
import com.woniu.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    //修改个人信息
    @PostMapping("/updateInfo")
    public ResponseResult<String> updateInfo(@RequestBody User user){
        System.out.println(user);
        if (userService.updateInfo(user)){
         return new ResponseResult<String>(200,null,"修改成功", null, null);
        }
      return new ResponseResult<String>(500,null,"修改失败，请稍后重试", null, null);

    }

    @RequestMapping("/findUser")
    public User findUser( @RequestBody int id){
        return userService.findUser(id);
    }

    //插入用户发起的养狗申请
    @RequestMapping("/dogApplication")
    public ResponseResult dogApplication(@RequestBody ApplyForTable applyForTable){
        ResponseResult responseResult = new ResponseResult();
        System.out.println(applyForTable);
        applyForTable.setApply_date(new Date());
        applyForTable.setID_type("身份证");
        if( userService.InsertApplyFor(applyForTable)){
            responseResult.setCode(200);
            responseResult.setMessage("申请成功");
        }else {
            responseResult.setCode(400);
            responseResult.setMessage("申请失败");
        }
        return responseResult;
    }

    //查询养狗审批的进度
    @RequestMapping("/raiseDog")
    public List<ApplyForTable> raiseDog(int id){
        return userService.raiseDog(id);
    }

    //查询该角色下所有的狗狗
    @RequestMapping("findNormalPet")
    public List<Dog> findNormalPet(int id){
        return userService.findNormalPet(id);
    }

    //插入用户注销狗狗的申请
    @RequestMapping("/cancelDog")
    public ResponseResult cancelDog(@RequestBody Cancellation cancellation){
        ResponseResult responseResult = new ResponseResult();
        System.out.println(cancellation);
        if( userService.cancelDog(cancellation)){
            responseResult.setCode(200);
            responseResult.setMessage("申请成功");
        }else {
            responseResult.setCode(400);
            responseResult.setMessage("申请失败");
        }
        return responseResult;
    }

    //查询所有用户注销狗狗的申请
    @RequestMapping("/selectCancelDog")
    public List<Cancellation> selectCancelDog(){
        return userService.selectCancelDog();
    }
}
